/*
 * Copyright (c) 2018. J4dream Created.
 */

package com.j4dream.property.dao;

import com.j4dream.property.Initializer.GeoDto;
import com.j4dream.property.model.KeyLabel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GeoDao {
    // key 为保留关键字
    @Insert("INSERT INTO geographic (k, label, pk) VALUES (#{key}, #{label}, #{pkey})")
    void insert(GeoDto geoDto);

    @Select("SELECT * FROM geographic WHERE pk=#{pkey}")
    @Results({
            @Result(column = "k", property = "key"),
            @Result(column = "pk", property = "pkey")
    })
    List<GeoDto> getGeosByPkey(@Param("pkey") String pkey);

    @Select("SELECT * FROM geographic WHERE k=#{key}")
    @Results({
            @Result(column = "k", property = "key"),
    })
    KeyLabel getGeoForKeyLable(@Param("key") String key);
}
